import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/category/:slug',
    name: 'Category',
    component: () => import('@/views/category/Index.vue')
  },
  {
    path: '/document',
    name: 'Document',
    component: () => import('@/views/document/Index.vue')
  },
  {
    path: '/document/category/:slug',
    redirect: to => {
      return {
        path: '/document',
        query: { category: to.params.slug }
      }
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/search/Index.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router 